import 'package:cached_network_image/cached_network_image.dart';
import 'package:du_application/http/HttpUtil.dart';
import 'package:du_application/http/Options.dart';
import 'package:du_application/model/OrderModel.dart';
import 'package:du_application/provide/AuthProvider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import 'package:shared_preferences/shared_preferences.dart';

class OrderSubmit extends StatelessWidget {
  final OrderModel orderModel;
  const OrderSubmit({Key key, this.orderModel}) : super(key: key);
  @override
  Widget build(BuildContext context) {
        Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
         submitOrder(int cardId,int addressId) async{
       await _prefs.then((ins) async{
    Options options =  Options(Provide.value<AuthProvider>(context).token);
    await HttpUtil.getInstance().post("/order/submit",data:{"cartId":cardId,"addressId":addressId},options:options.options).then((data) {
   
    });
  });
  }
    return Scaffold(
      appBar: AppBar(
        title: Text("确认订单"),
      ),
      bottomNavigationBar: BottomAppBar(
        child: Container(
          height: ScreenUtil().setHeight(150),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
             children: <Widget>[
               
             Row(
              children: <Widget>[
              Text("实付款:",style: TextStyle(color: Colors.red),),
              Text("￥",style: TextStyle(color: Colors.red,fontSize: ScreenUtil().setSp(15),fontWeight: FontWeight.bold),),
              Text("${orderModel.data.cart.price}",style: TextStyle(color: Colors.red,fontSize: ScreenUtil().setSp(40),fontWeight: FontWeight.bold),),
              ],
              
            ),
            InkWell(
              onTap:(){
                submitOrder(orderModel.data.cart.id,orderModel.data.address.id);

              },
              child:  Container(
              margin: EdgeInsets.only(right: ScreenUtil().setSp(10)),
              padding: EdgeInsets.symmetric(vertical: ScreenUtil().setSp(10)),
              width: ScreenUtil().setWidth(200),
              color: Colors.cyan[400],
              child: Text("提交订单",textAlign: TextAlign.center,style: TextStyle(color:Colors.white),),
            ) ,
            )
          
             ],
          
          )
        ),
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            Card(
              child: Row(
                children: <Widget>[
                  Container(
                    width: ScreenUtil().setWidth(300),
                    height: ScreenUtil().setHeight(250),
                    padding: EdgeInsets.all(ScreenUtil().setSp(10)),
                    child: CachedNetworkImage(
                      height: ScreenUtil().setWidth(200),
                      width: ScreenUtil().setWidth(320),
                      imageUrl: orderModel.data.cart.picUrl,
                      fit: BoxFit.fitWidth,
                      placeholder: (context, url) =>
                          Image.asset('assets/loading.jpg'),
                    ),
                  ),
                  Stack(
                    children: <Widget>[
                      Container(
                          width: ScreenUtil().setWidth(720),
                          height: ScreenUtil().setWidth(180),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Container(
                                width: ScreenUtil().setWidth(710),
                                child: Text("${orderModel.data.cart.goodsName}",
                                    maxLines: 2),
                              ),
                              Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: <Widget>[
                                  Container(
                                      width: ScreenUtil().setWidth(200),
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: <Widget>[
                                          Container(
                                              child: Text(
                                                  "${orderModel.data.cart.specifications.join("")}")),
                                          Container(
                                              child: Text(
                                                  "数量 x${orderModel.data.cart.number}")),
                                        ],
                                      )),
                                  Row(
                                    children: <Widget>[
                                      Text(
                                        "￥",
                                        style: TextStyle(
                                            fontWeight: FontWeight.bold,
                                            fontSize: ScreenUtil().setSp(15)),
                                      ),
                                      Text("${orderModel.data.cart.price}",
                                          style: TextStyle(
                                              fontWeight: FontWeight.bold,
                                              fontSize:
                                                  ScreenUtil().setSp(30))),
                                    ],
                                  )
                                ],
                              ),
                            ],
                          ))
                    ],
                  )
                ],
              ),
            ),
           Card(
              child: orderModel.data.address!=null?Container(
                padding: EdgeInsets.symmetric(
                    horizontal: ScreenUtil().setSp(10),
                    vertical: ScreenUtil().setSp(10)),
                width: ScreenUtil().setWidth(1080),
                height: ScreenUtil().setHeight(190),
                child: Row(
                  children: <Widget>[
                    Icon(Icons.location_on,color:Colors.cyan[400],),
                Container(
                 height: ScreenUtil().setHeight(170),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Container(
                          width: ScreenUtil().setWidth(960),
                                   height: ScreenUtil().setHeight(100),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: <Widget>[
                           Text("收货人:${orderModel.data.address.name}",style: TextStyle(fontWeight: FontWeight.bold),),
                              Row(
                                children: <Widget>[
                                  Text(
                                      "${orderModel.data.address.tel.substring(0, 3)}****${orderModel.data.address.tel.substring(7)}" ,style: TextStyle(fontWeight: FontWeight.bold),),
                                Container(
                                  width: ScreenUtil().setWidth(70),
                                  margin: EdgeInsets.symmetric(horizontal: ScreenUtil().setSp(10)),
                                  child: Icon(Icons.settings,
                                      color: Colors.cyan[400],size: ScreenUtil().setSp(40),)
                                )
                                ],
                              )
                            ],
                          )),
                        Container(
                        width: ScreenUtil().setWidth(800),
                         padding: EdgeInsets.symmetric(
                          horizontal: ScreenUtil().setSp(5)),
                          child: Text(
                          "${orderModel.data.address.addressDetail}",maxLines: 2,
                           style: TextStyle(color: Colors.grey[400],),
                          )),
                          
                    ],
                  )
                )
                  ],
                ),
              ):Container(
                child: Text("请添加地址"),
              ),
            )
          ],
        ),
      ),
    );
 
  }
  
}
